package cz.proks.easyhelpdesk.gae.api.impl.dbo;

import org.springframework.beans.BeanUtils;

import cz.proks.easyhelpdesk.gae.api.impl.dbo.base.ConvertibleDbo;
import cz.proks.easyhelpdesk.gae.api.impl.dbo.base.IdentifiableModelDbo;


public class Helpdesk extends cz.proks.easyhelpdesk.api.model.Helpdesk implements IdentifiableModelDbo, ConvertibleDbo<cz.proks.easyhelpdesk.api.model.Helpdesk>{	
	private User owner;	
	   	
    @Override
    public Long getOwnerId() {        
        return super.getOwnerId();
    }

    @Override
    public void setOwnerId(Long ownerId) {
        super.setOwnerId(ownerId);
        
        if (ownerId == null)
            owner = null;
        else {
            owner = new User();      
            owner.setId(ownerId);
        }        
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
        super.setOwnerId(owner != null ? owner.getId() : null);
    }
	
    public void toDbo(cz.proks.easyhelpdesk.api.model.Helpdesk helpdesk) {
        BeanUtils.copyProperties(helpdesk, this);
    }
    
    public cz.proks.easyhelpdesk.api.model.Helpdesk asDomain() {
        cz.proks.easyhelpdesk.api.model.Helpdesk helpdesk = new cz.proks.easyhelpdesk.api.model.Helpdesk();
        BeanUtils.copyProperties(this, helpdesk, new String[] {"owner"});        
        return helpdesk;
    }
}
